package tw.edu.tku.im.maze;

import org.json.JSONException;
import org.json.JSONObject;

public class MarkReq extends ReqPacket {
   
   int roomID;
   String userID;
   int ticket;
   String lastTimestamp;
   MazeCell mark; 
   boolean markAction;
   
   public MarkReq(int roomID, String userID, int ticket, MazeCell mark, 
                  boolean markAction) 
   {
      this(roomID, userID, ticket, null, mark, markAction);
   }

   public MarkReq(int roomID, String userID, int ticket, String lastTimestamp,
                  MazeCell mark, boolean markAction) 
   {
      this.roomID = roomID;
      this.userID = userID;
      this.ticket = ticket;
      this.lastTimestamp = lastTimestamp;
      this.mark = mark;
      this.markAction = markAction;
   }

   
   public int getRoomID() {
      return roomID;
   }

   public void setRoomID(int roomID) {
      this.roomID = roomID;
   }

   public String getUserID() {
      return userID;
   }

   public void setUserID(String userID) {
      this.userID = userID;
   }

   public int getTicket() {
      return ticket;
   }

   public void setTicket(int ticket) {
      this.ticket = ticket;
   }

   public String getLastTimestamp() {
      return lastTimestamp;
   }

   public void setLastTimestamp(String lastTimestamp) {
      this.lastTimestamp = lastTimestamp;
   }

   public MazeCell getMark() {
      return mark;
   }

   public void setMark(MazeCell mark) {
      this.mark = mark;
   }

   public boolean isMarkAction() {
      return markAction;
   }

   public void setMarkAction(boolean markAction) {
      this.markAction = markAction;
   }

   @Override
   public String toJSONString() throws JSONException {
      JSONObject parameter = new JSONObject();
      JSONObject jsonObj = new JSONObject();
      parameter.put("roomID", this.roomID);
      parameter.put("userID", this.userID);
      parameter.put("ticket", this.ticket);
      parameter.put("mark", new JSONObject(this.mark.toJSONString()));
      parameter.put("markAction", this.markAction);
      if(this.lastTimestamp!=null) {
         parameter.put("lastTimestamp", this.lastTimestamp);
      }
      jsonObj.put("parameter", parameter);
      jsonObj.put("action", "mark");
      return jsonObj.toString();
   }
   
   @Override
   public String getPacketName() {
      return "mark";
   }

}
